﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Tongiao.Manager;
using Tongiao.ManagerBase;

public partial class admin_Category_CategoryList : System.Web.UI.UserControl
{

    /// <summary>
    /// Loai category : NEWS, PROD
    /// </summary>
    public string CatType
    {
        get { return hidCatType.Value; }
        set
        {
            hidCatType.Value = value;
            switch (hidCatType.Value)
            {
                case "NEWS": lblTitle.Text = "DANH MỤC TIN TỨC";
                    break;
                case "PROD": lblTitle.Text = "DANH MỤC SẢN PHẨM";
                    break;

            }
        }
    }

    public string GetDetailLink(object id)
    {
        switch (CatType)
        {
            case "NEWS": return "?control=NaddCat&id=" + id;
                break;
            case "PROD": return "?control=ProAddCat&id=" + id;
                break;

        }
        return "#";
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["control"] == "NCatList")
                CatType = "NEWS";
            else
                CatType = "PROD";
            LoadCategoryListByCatType();
          
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        switch (CatType)
        {
            case "NEWS": Response.Redirect("?control=NaddCat");
                break;
            case "PROD": Response.Redirect("?control=ProAddCat");
                break;

        }
    }


    void LoadCategoryListByCatType()
    {
        DataTable dtCat = Tg_CategoryManager.CreateInstant().getAllCategoryListByCatType(CatType);
        if (dtCat.Rows.Count >= 0)
        {
            rep.DataSource = dtCat;
            rep.DataBind();
        }
    }
    protected void rep_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "del":
                Tg_CategoryManager.CreateInstant().DeleteById(new Guid(e.CommandArgument.ToString()));

                LoadCategoryListByCatType();
                break;
        }
    }
}
